const {
  DataTypes
} = require('sequelize');
module.exports = sequelize => {
  const attributes = {
    userId: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: null,
      comment: "用户ID",
      primaryKey: false,
      field: "user_id",
      autoIncrement: false,
      references: {
        key: "id",
        model: "sys_user_model"
      }
    },
    roleId: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: null,
      comment: "角色ID",
      primaryKey: false,
      field: "role_id",
      autoIncrement: false,
      references: {
        key: "id",
        model: "sys_role_model"
      }
    }
  };
  const options = {
    tableName: "sys_user_role",
    comment: "",
    indexes: []
  };
  const SysUserRoleModel = sequelize.define("sys_user_role_model", attributes, options);
  
  // 添加关联关系
  SysUserRoleModel.associate = function(models) {
    SysUserRoleModel.belongsTo(models.sys_user_model, {
      foreignKey: 'userId'
    });
    SysUserRoleModel.belongsTo(models.sys_role_model, {
      foreignKey: 'roleId'
    });
  };
  
  return SysUserRoleModel;
};